package com.sync.syncmasterdata.customer.repository.u8rep;

import com.sync.syncmasterdata.customer.entity.u8.CustomerEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 获取客户信息
 */
@Repository
public interface CustomerRepository extends JpaRepository<CustomerEntity,String> {

    /**
     * 获取客户编号 by 客户姓名
     * @param cCusName
     * @return
     */
    @Query(nativeQuery = true, value= "select cCusCode from customer where  cCusName=:cCusName")
    String getCusCode(@Param(value = "cCusName") String cCusName);

    @Query(nativeQuery = true, value= "select cCusCode,dEndDate from customer where cCusName=:cCusName")
    Map<String,Object> getCusCodeAndStop(@Param(value = "cCusName") String cCusName);

    /**
     * 传入crmguid+客户名称，锁定唯一客户
     * @param cCusName
     * @param guid
     * @return
     */
    @Query(nativeQuery = true, value = "select cCusCode from Customer where dEndDate is null and cCusName=:cCusName or cCusDefine7=:guid")
    List<String> getCusCodeByNameAndGuid(@Param(value = "cCusName") String cCusName,@Param(value="guid") String guid);
}
